/**
 * This js is different from utils.js. This js doesn't have any 'import'.
 */

 export default {
    getAstroFromBirth(birth){
        if (~birth.indexOf("-")) {
            let birthday = birth.split("-");
            let month = parseInt(birthday[1]);
            let day = parseInt(birthday[2]);

            return this.getAstro(month, day);
        }
        return "魔蝎座";
    },
    getAstro(m, d) {
        return "魔羯水瓶双鱼白羊金牛双子巨蟹狮子处女天秤天蝎射手魔羯".substr(m*2-(d<"102123444543".charAt(m-1)- -19)*2,2) + '座';
    },
    newBirth(age = 18, year = 2000){
        const date = new Date();
        year = year || (date.getFullYear() - age);
        const month = date.getMonth();
        const day = date.getDate();
        const d = new Date(year, month, day);
        return `${d.getFullYear()}-${d.getMonth()+1}-${d.getDate()}`;
    },
    getAge(birthStr) {
        // console.log('birthStr: ' + birthStr);
        if (birthStr.indexOf("-") > 0) {
            const today = new Date();
            const [birthYear, birthMonth, birthDay] = birthStr.split('-');
            const birthDate = new Date(birthYear, birthMonth-1, birthDay);
            let age = today.getFullYear() - birthDate.getFullYear();
            const m = today.getMonth() - birthDate.getMonth();
            if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
                age--;
            }
            age = age.toString();
            return age + '岁';
        }
        return 18 + "岁";
    },
    // return a int between min and max number.
    randomIntRange(min, max){
        return Math.floor(min + (max - min)*Math.random());
    }
 };